import React from 'react';
import ReactDOM from 'react-dom';

import {Router, Route, useRouterHistory} from 'react-router';
import {createHashHistory} from 'History';
import {Provider} from 'mobx-react';
import {RouterStore, syncHistoryWithStore} from 'mobx-react-router';

const browserHistory = useRouterHistory(createHashHistory)({
    queryKey: '_key',
    basename: '/',
});

const routing = new RouterStore();

const history = syncHistoryWithStore(browserHistory, routing);
window.weaHistory = history;

import {WeaDebugRouteMenu} from 'ecCom';
WeaDebugRouteMenu.defaultProps.showRouteLev = 3;

import Module from './index';

const stores = {
    routing,
    ...Module.store,
};

const Home = props => props.children;

const Root = () => (
    <Provider {...stores}>
        <Router history={history}>
            <Route path='/' component={WeaDebugRouteMenu}>
                <Route path='main' component={Home}>
                    {Module.Route}
                </Route>
            </Route>
        </Router>
    </Provider>
);

ReactDOM.render(<Root/>, document.getElementById('container'));
